<template>
  <el-row :gutter="15">
    <el-col :span="24">
      <el-card>
        <div slot="header" class="clearfix">发起仓库异常</div>
        <el-form ref="searchForm" class="el-form-col search-form" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="packNo">
                <el-input v-model="search.packNo" placeholder="包件编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="packName">
                <el-input v-model="search.packName" placeholder="包件名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="cargoOwnerName">
                <el-input v-model="search.cargoOwnerName" placeholder="商家名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-lg-only hidden-xl-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="reset('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="manuName">
                <el-input v-model="search.manuName" placeholder="厂家名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="belongProduct">
                <el-input v-model="search.belongProduct" placeholder="所属产品"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-md-only hidden-sm-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="reset('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="locationName">
                <el-input v-model="search.locationName" placeholder="库位"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </el-col>

    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/orderAbnormal/getStorePacksList"
        :columns="columns"
      >
        <template slot="column">
          <el-table-column fixed="right" width="80px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="launch(scope.row)"
              ><span>发起异常</span></el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
    <Launch-modal ref="LaunchModal" :obj="obj" @refresh="refresh"></Launch-modal>
  </el-row>
</template>
<script>
import {copy} from '@/utils'
import {getAllWarehouse} from '@/utils/selectOptions'
import moment from 'moment'
import LaunchModal from '@/views/oms/abnormal/launch/LaunchModal.vue'

export default {
  name: 'abnormalLaunchIndex',
  components: {
    LaunchModal
  },
  data() {
    return {
      searchLoading: false,
      search: {
        packNo: '',
        packName: '',
        cargoOwnerName: '',
        manuName: '',
        belongProduct: '',
        locationName: ''
      },
      searchOpen: false,
      warehouseIdArr: [],
      obj: {},
      columns: [
        {
          label: '库位',
          data: 'locationName'
        },
        {
          label: '商家名称',
          data: 'cargoOwnerName'
        },
        {label: '厂家名称', data: 'manuName'},
        {label: '所属产品', data: 'belongProduct'},
        {
          label: '包件编号',
          data: 'packNo'
        },
        {
          label: '包件名称',
          data: 'packName'
        },
        {
          label: '规格',
          data: 'packStandard'
        },
        {
          label: '颜色',
          data: 'packColor'
        },
        {
          label: '风格',
          data: 'packStyle'
        },
        {
          label: '单位',
          data: 'packUnit'
        },
        {
          label: '实际包件',
          data: 'packRealNum'
        }
      ]
    }
  },
  created() {
    getAllWarehouse().then(arr => {
      this.warehouseIdArr = arr
    })
  },
  methods: {
    disabledDate(time) {
      return time.getTime() < moment(this.search.allocationStartTime).format('x')
    },
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    reset() {
      this.$refs.searchForm.resetFields()
    },
    refresh() {
      this.searchFunc()
    },
    launch(data) {
      this.obj = data
      this.$refs.LaunchModal.show()
    }
  }
}
</script>
